Skip to content

Conversation

yelninei
Copy link
Contributor

Linux:

  [
 {
    "type": "InitSystem",
    "result": {
      "name": "shepherd",
      "exe": "/gnu/store/zj0fawhffs6h1vcxi8djanjvhjas2v5l-shepherd-1.0.6/bin/shepherd",
      "version": "1.0.6",
      "pid": 1
    }
  },
  {
    "type": "Kernel",
    "result": {
      "architecture": "x86_64",
      "name": "Linux",
      "release": "6.15.9",
      "version": "#1 SMP PREEMPT_DYNAMIC 1",
      "displayVersion": "",
      "pageSize": 4096
    }
  }
]

Hurd:

[
  {
    "type": "InitSystem",
    "result": {
      "name": "shepherd",
      "exe": "/gnu/store/zzlrf6iy7rwq2fs6kl99jhmfa5dbfxcx-shepherd-1.0.6/bin/shepherd",
      "version": "1.0.6",
      "pid": 1
    }
  },
  {
    "type": "Kernel",
    "result": {
      "architecture": "i686-AT386",
      "name": "GNU",
      "release": "0.9",
      "version": "GNU-Mach 1.8/Hurd-0.9",
      "displayVersion": "",
      "pageSize": 4096
    }
  }
]

// The first line in the output might not contain the version
if (!ffStrbufStartsWithS(&result->version, "shepherd"))
ffStrbufSubstrAfterFirstC(&result->version, '\n');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This skips over the warning about missing signalfd support on Hurd

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If shepherd version always comes at the end, I prefer ffStrbufSubstrAfterLastC(&result->version, ' ');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some licensing information in the lines afterwards that I ommitted.

 shepherd --version
shepherd (GNU Shepherd) 1.0.6
Copyright (C) 2025 the Shepherd authors
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

@yelninei yelninei force-pushed the dev branch 2 times, most recently from d0752b2 to 68bd10f Compare August 25, 2025 14:55
@yelninei
Copy link
Contributor Author

the loop is missing error checking when there is no */shepherd argument.
It also assumes that each arg is properly nullterminated and copies that as well.

// guile --no-auto-compile shepherd
// find the shepherd script in /proc/1/cmdline
const char* tmp = result->exe.chars;
while(!ffStrbufEndsWithS(&result->exe, "/shepherd"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition, as what I said before, you should search for /path/to/shepherd, instead of assuming it's the 2nd argument

this iterates the args until it finds the one that points to the script.

Or what else did you mean by your previous comment?

@CarterLi
Copy link
Member

Please upload the content of /proc/1/stat and /proc/1/cmdline, so I can test it myself.

@yelninei
Copy link
Contributor Author

Please upload the content of /proc/1/stat and /proc/1/cmdline, so I can test it myself.

 /proc/1/stat (linux)
1 (shepherd) S 0 0 0 0 -1 4194560 24494 128275 242 2366 54 39 189 119 20 0 4 0 4 176713728 16368 18446744073709551615 1 1 0 0 0 0 81923 4096 545260576 0 0 0 17 2 0 0 0 0 0 0 0 0 0 0 0 0 0
/proc/1/stat (hurd)
1 (guile) S 1 1 1 0 0 0 0 0 0 0 36 20 0 0 20 0 3 0 175621420597 214646784 5619 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
 /proc/1/cmdline (linux)
/gnu/store/37m0a0ydy74wl2qrf2w1jdgqhxwbaxac-guile-3.0.9/bin/guile\0--no-auto-compile\0/gnu/store/zj0fawhffs6h1vcxi8djanjvhjas2v5l-shepherd-1.0.6/bin/shepherd\0--config\0/gnu/store/vzidy9ykg11hxiyfhambk7h3ws9sr7bv-shepherd.conf\0

On hurd the cmdline is the same (just with different gnu/store paths)

@CarterLi
Copy link
Member

Please test if 7a87638 works for you

@yelninei
Copy link
Contributor Author

Thanks, it works for me.

Shepherd is detected correctly as init (correct name, exe and version) on

  • guix x86_64 linux
  • guix i686 hurd (native + cross build)
  • guix x86_64 hurd (native + cross build)

@yelninei yelninei closed this Aug 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants